package office.service.hr.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import office.action.hr.form.CheckIdeaForm;
import office.bo.hr.impl.CheckIdea;
import office.domainset.BizDomainProviderSetImpl;
import office.service.finance.ILoanService;
import office.service.finance.INoteService;
import office.service.finance.IWeekCashService;
import office.service.hr.IBecomeRegularService;
import office.service.hr.ICheckIdeaService;
import office.service.hr.IPurchaseEntryService;
import office.service.hr.IQuitEntryService;
import office.service.hr.IRecruitPlanService;
import office.service.hr.IStationChangeService;
import office.service.person.ILeaveService;
import office.service.person.ITripService;
import platform.common.exception.BusinessException;
import platform.common.service.impl.BaseBizServiceImpl;

public class CheckIdeaServiceImpl extends BaseBizServiceImpl implements ICheckIdeaService{
	private IBecomeRegularService becomeRegularService;
	private IStationChangeService stationChangeService;
	private IQuitEntryService quitEntryService;
	private IWeekCashService weekCashService;
	private INoteService noteService;
	private ILoanService loanService;
	private ILeaveService leaveService;
	private ITripService tripService;
	private IRecruitPlanService recruitPlanService;
	private IPurchaseEntryService purchaseEntryService;//采购service
	
	

	/**
	 * 保存审批意见
	 * @throws BusinessException
	 */
	public void saveCheckIdea(CheckIdeaForm checkIdeaForm)throws BusinessException{
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			CheckIdea checkIdea = (CheckIdea)domainProviderSetImpl.getCheckIdeaDP().newEmptyObj();
			checkIdea.generatorUUID();
			checkIdea.setCheck(checkIdeaForm.isCheck());
			checkIdea.setCheckFolwId(checkIdeaForm.getCheckFolwId());
			checkIdea.setCheckMemo(checkIdeaForm.getCheckMemo());
			checkIdea.setCheckUserId(checkIdeaForm.getCheckUserId());
			
			Calendar c = Calendar.getInstance();
			SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			checkIdea.setCheckTime(time.format(c.getTime()));
			
			
			checkIdea.store(domainProviderSet);
			String classFlag = checkIdeaForm.getClassFlag();
			if(classFlag.equals("becomeRegular")){
				becomeRegularService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId());
			}else if(classFlag.equals("stationChange")){
				stationChangeService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId());
			}else if(classFlag.equals("quitEntry")){
				quitEntryService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId());
			}else if(classFlag.equals("loan")){
				loanService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId(),checkIdeaForm.getClassFlag());
			}else if(classFlag.equals("note")){
				noteService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId(),checkIdeaForm.getClassFlag());
			}else if(classFlag.equals("weekCash")){
				weekCashService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId(),checkIdeaForm.getClassFlag());
			}else if(classFlag.equals("leave")){
				leaveService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId(),checkIdeaForm.getClassFlag());
			}else if(classFlag.equals("trip")){
				tripService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId(),checkIdeaForm.getClassFlag());
			}else if(classFlag.equals("recruitPlan")){
				recruitPlanService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId(),checkIdeaForm.getClassFlag());
			}else if(classFlag.equals("purchaseEntry")){
				purchaseEntryService.checkData(checkIdeaForm.isCheck(), checkIdeaForm.getCheckFolwId(),checkIdeaForm.getClassFlag());
			}
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("保存审批意见信息失败!", e);
		}
	}
	
	/**
	 * 获取某个审批对象的审批意见
	 * @param checkFolwId
	 * @return
	 * @throws BusinessException
	 */
	public List getByCheckFolwId(String checkFolwId)throws BusinessException{
		List listData = null;
		try {
			BizDomainProviderSetImpl domainProviderSetImpl = (BizDomainProviderSetImpl) domainProviderSet;
			Map map = new HashMap();
			map.put("checkFolwId", checkFolwId);
			listData = domainProviderSetImpl.getDao().findByHqlNameAndDomian(domainProviderSetImpl.getCheckIdeaDP(), "findByCheckFolwId", map);
		} catch (Exception e) {
			log.error("", e);
			throw this.handleBusinessServiceException("获取审批对象的审批意见信息失败!", e);
		}
		return listData;
	}

	public IBecomeRegularService getBecomeRegularService() {
		return becomeRegularService;
	}

	public void setBecomeRegularService(IBecomeRegularService becomeRegularService) {
		this.becomeRegularService = becomeRegularService;
	}

	public IStationChangeService getStationChangeService() {
		return stationChangeService;
	}

	public void setStationChangeService(IStationChangeService stationChangeService) {
		this.stationChangeService = stationChangeService;
	}

	public IQuitEntryService getQuitEntryService() {
		return quitEntryService;
	}

	public void setQuitEntryService(IQuitEntryService quitEntryService) {
		this.quitEntryService = quitEntryService;
	}

	public IWeekCashService getWeekCashService() {
		return weekCashService;
	}

	public void setWeekCashService(IWeekCashService weekCashService) {
		this.weekCashService = weekCashService;
	}

	public INoteService getNoteService() {
		return noteService;
	}

	public void setNoteService(INoteService noteService) {
		this.noteService = noteService;
	}

	public ILoanService getLoanService() {
		return loanService;
	}

	public void setLoanService(ILoanService loanService) {
		this.loanService = loanService;
	}

	public ILeaveService getLeaveService() {
		return leaveService;
	}

	public void setLeaveService(ILeaveService leaveService) {
		this.leaveService = leaveService;
	}

	public ITripService getTripService() {
		return tripService;
	}

	public void setTripService(ITripService tripService) {
		this.tripService = tripService;
	}

	public IRecruitPlanService getRecruitPlanService() {
		return recruitPlanService;
	}

	public void setRecruitPlanService(IRecruitPlanService recruitPlanService) {
		this.recruitPlanService = recruitPlanService;
	}

	public IPurchaseEntryService getPurchaseEntryService() {
		return purchaseEntryService;
	}

	public void setPurchaseEntryService(IPurchaseEntryService purchaseEntryService) {
		this.purchaseEntryService = purchaseEntryService;
	}
	
	
}
